/**
 * Created by zzy on 2017/10/27.
 */
import {observer} from "mobx-react";
import {observable, action, computed, observe} from 'mobx'
import NetRequestLuo from '../util/NetRequest'
import addressMgrStore from '../../js/store/AddrMgrStore'

class WaterStationStore{
    @observable shoplist=[];
    @observable loading=true;
    constructor(){
    }
    @action setShopList(shoplist){
        this.shoplist=shoplist;
    }
    @action getShopList(){
        this.loading=true;
        let param={
            latitude: addressMgrStore.activeAddress.latitude,
            longtitude: addressMgrStore.activeAddress.longitude,
            cityName: '北京'
        };
        NetRequestLuo.getStationList(param).then((data)=>{
            LOG('附近店铺--------'+JSON.stringify(data));
            this.shoplist=this.sortShopList(data);
            this.loading=false;
        });
    }
    @computed get ShopList(){
        return this.shoplist;
    }
     sortShopList(list){//按距离排序
         let shopList=[];
         for(var i=0;i<list.length;i++){
             list[i].distance=list[i].distance.substring(0,list[i].distance.length-2)*1;
         }
         shopList=list.sort(function (a,b) {
             return parseFloat(a.distance)-parseFloat(b.distance)
         });
         for(var i=0;i<shopList.length;i++){
             shopList[i].distance=shopList[i].distance+'km';
         }
         return shopList;
     }
}
let waterStationStore=new WaterStationStore();
export default waterStationStore